package cn.gok.manage.service.impl;

import cn.gok.dao.OrderMapper;
import cn.gok.dao.ProductMapper;
import cn.gok.dao.UserMapper;
import cn.gok.manage.service.CountService;
import cn.gok.manage.web.vo.CountVO;
import cn.gok.pojo.Count;
import cn.gok.util.ResultData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CountServiceImpl implements CountService {

    @Autowired
    OrderMapper orderMapper;

    @Autowired
    ProductMapper productMapper;

    @Autowired
    UserMapper userMapper;

    CountVO countVO = null;

    @Override
    public ResultData count() {
        int orderCount = orderMapper.orderCount();

        int productCount = productMapper.productCount();

        int userCount = userMapper.userCount();

        countVO = new CountVO();

        countVO.setUserCount(userCount);
        countVO.setProductCount(productCount);
        countVO.setOrderCount(orderCount);

        if (orderCount != 0 && productCount != 0 && userCount != 0){
            return ResultData.createData(countVO);
        }
       return ResultData.fail("出错啦");
    }
}
